package zx.x.modules.app.controller;

import java.text.SimpleDateFormat;
import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import zx.x.modules.app.dao.MerchantRoomTypeDao;
import zx.x.modules.app.entity.MerchantEntity;
import zx.x.modules.app.entity.MerchantRoomEntity;
import zx.x.modules.app.entity.MerchantRoomTypeEntity;
import zx.x.modules.app.entity.UserEntity;
import zx.x.modules.app.service.MerchantRoomTypeService;
import zx.x.common.utils.PageUtils;
import zx.x.common.utils.R;
import zx.x.modules.app.utils.Sc;
import zx.x.modules.app.vo.MerchantRoomTypeVo;

import static zx.x.modules.app.utils.Sc.subList;

/**
 * 商户房间类型
 *
 * @author x
 * @email x
 * @date 2022-09-23 10:25:40
 */
@RestController
@RequestMapping("/app/merchantroomtype")
public class MerchantRoomTypeController {
    @Autowired
    private MerchantRoomTypeService merchantRoomTypeService;
    @Autowired
    private MerchantRoomTypeDao dao;

    /**
     * 酒店详情房间列表
     */
    @RequestMapping("/list")
    public R list(MerchantRoomTypeVo obj) throws Exception {
        obj.setYdTime(obj.getYdTime().substring(0,obj.getYdTime().lastIndexOf(",")));
        List<MerchantRoomTypeVo> list = merchantRoomTypeService.selectRoomTypeList(obj);
        return R.ok().put("page", subList(list,obj.getPage(),obj.getLimit())).put("total",list.size());
    }


    /**
     * 信息
     */
    @RequestMapping("/info")
    public R info(Integer id){
        MerchantRoomTypeEntity merchantRoomType = merchantRoomTypeService.getById(id);
        return R.ok().put("merchantRoomType", merchantRoomType);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(MerchantRoomTypeEntity merchantRoomType){
        merchantRoomTypeService.save(merchantRoomType);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(MerchantRoomTypeEntity merchantRoomType){
        merchantRoomTypeService.updateById(merchantRoomType);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(Integer[] ids){
        merchantRoomTypeService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 民宿room列表
     */
    @RequestMapping("/selectMsRoomTypeList")
    public R selectMsRoomTypeList(MerchantRoomTypeVo obj) throws Exception {
        obj.setYdTime(obj.getYdTime().substring(0,obj.getYdTime().lastIndexOf(",")));
        List<MerchantRoomTypeVo> list = merchantRoomTypeService.selectMsRoomTypeList(obj);

        List<MerchantRoomEntity> listB = new ArrayList<MerchantRoomEntity>();
        for (int i=0;i<list.size();i++){
            for (int j=0;j<list.get(i).getMerchantRoomList().size();j++){
                list.get(i).getMerchantRoomList().get(j).setTp(list.get(i).getImage());
            }
            listB.addAll(list.get(i).getMerchantRoomList());
        }
        return R.ok().put("page", subList(list,obj.getPage(),obj.getLimit())).put("total",list.size()).put("roomList",listB);
    }
}
